<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>

    <style>
        *{
            margin:0;
            padding:0;
        }

        .box-px{
            width:320px;
            height:160px;
            background: red;
        }

        .box-rem{
            /**320/16 = 20**/
            width:20rem;
            height:10rem;
            background: green;
        }
    </style>
</head>
<body>
    <div class="box-px">
        hello px
    </div>
    <div class="box-rem">
        hello rem
    </div>
    <script>
        //窗口大小改变之后设置html字体大小  视口的宽度/20 = html字体大小
        function setRem(){
            console.log("====");
            let clientWidth = document.documentElement.clientWidth; //获取视口的宽度

            let htmlDom = document.documentElement;

            htmlDom.style.fontSize = clientWidth/20 + 'px';
        }

        setRem();

        window.onresize = setRem; 

        // window.onresize = function(){
        //     console.log("===")
        // } 
    </script>
</body>
</html>